import React, { Component, Fragment } from 'react';
import { connect } from 'react-redux';

import { actionCreators } from './store';

class Index extends Component {

	componentDidMount(){
		const { getTopicList } = this.props;
		const params = {
			page: 1,
			tab: 'ask',
			limit: 30,
			mdrender: 'false',
		};
		getTopicList(params);
	}

	render() {
		const { topicList } = this.props;
		return(
			<Fragment>
				{
					topicList.map((item, index)=>{
						return <div key={item.get('create_at')}>{item.get('title')}</div>
					})
				}
			</Fragment>
		)
	}
}

const mapStateToProps = (state) => {
	return {
		topicList: state.getIn(['header', 'topicList']),
	}
}

const mapDispathToProps = (dispatch) => {
	return {
		getTopicList(params) {
			dispatch(actionCreators.getTopics(params));
		},
	}
}

export default connect(mapStateToProps, mapDispathToProps)(Index);
